<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form ref="formValidate" v-loading="fullscreenLoading" class="formValidate mt20" :rules="ruleValidate" :model="formValidate" label-width="140px" @submit.native.prevent>
        <el-row :gutter="24">
          <el-row v-bind="grid2">
            <el-form-item label="关于我们：" prop="content">
              <Tinymce v-model="formValidate.content"></Tinymce>
            </el-form-item>
          </el-row>
        </el-row>
        <el-form-item>
          <el-button type="primary" class="submission" @click="handleSubmit('formValidate')" v-hasPermi="['admin:system:page:save']">提交</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
  import * as pageApi from '@/api/pageApi.js'
  import Tinymce from '@/components/Tinymce/index'
  import { clearTreeData } from '@/utils/ZBKJIutil'
  //import Templates from "../../appSetting/wxAccount/wxTemplate/index";
  import {Debounce} from '@/utils/validate'
  import {getToken} from "@/utils/auth";
  import { editContent, getContent } from '@/api/pageApi.js'
  const defaultObj = {
    content: '',
    id:null
  }

  export default {
    //name: 'ProductProductAdd',
    components: {Templates, Tinymce },
    data() {
      return {
        isDisabled: this.$route.params.isDisabled==='1'?true:false,
        fullscreenLoading: false,
        formValidate: Object.assign({}, defaultObj),
        //el-col响应式布局
        grid2: {
          xl: 12,
          lg: 12,
          md: 12,
          sm: 24,
          xs: 24
        },
        grid: {
          xl: 8,
          lg: 8,
          md: 12,
          sm: 24,
          xs: 24
        },
        isBtn: false,
        ruleValidate: {
          content: [
            { required: true, message: '请输入内容', trigger: 'blur' }
          ],
        },
        tempRoute: {},
        myHeaders: { "X-Token": getToken() },
      }
    },
    computed: {
    },
    watch: {
    },
    created() {
      this.tempRoute = Object.assign({}, this.$route)
    },
    mounted() {
      //this.setTagsViewTitle()
      this.getInfo()
    },
    methods: {
      // 详情
      getInfo () {
        this.fullscreenLoading = true
        pageApi.getContent(this.$route.params.id).then(async res => {
          let info = res
          this.formValidate = {
            content: info.content,
            id:info.id
          }
          this.fullscreenLoading = false
        }).catch(res => {
          this.fullscreenLoading = false
          this.$message.error(res.message);
        });
      },

      // 提交
      handleSubmit:Debounce(function(name) {
        this.$refs[name].validate((valid) => {
          if (valid) {
            this.fullscreenLoading = true

            pageApi.editContent(this.formValidate).then(async res => {
              this.$message.success('编辑成功');
              setTimeout(() => {
                this.$router.push({ path: '/operation/pageConfig' });
              }, 500);
              this.fullscreenLoading = false
            }).catch(res => {
              this.fullscreenLoading = false
            })
          } else {
            if(!this.formValidate.content){
              this.$message.warning("请填写内容！");
            }
          }
        });
      }),
      // 表单验证
      validate (prop, status, error) {
        if (status === false) {
          this.$message.warning(error);
        }
      },
    }
  }
</script>
<style scoped lang="scss">
  .el-form-item{
    margin:0 auto 30px auto;
  }
  .definedArea{
    width:125px !important;
    height:125px !important;
    border:1px #dcdfe6 dashed !important;
  }
  .tips{
    color: #c0c4cc;
    font-size:14px;
  }
  .disLabel{
    ::v-deep.el-form-item__label{
      margin-left: 36px !important;
    }
  }
  .disLabelmoren{
    ::v-deep.el-form-item__label{
      margin-left: 120px !important;
    }
  }
  .priamry_border{
    border: 1px solid #1890FF;
    color: #1890FF;
  }
  .color-item{
    height: 30px;
    line-height: 30px;
    padding: 0 10px;
    color:#fff;
    margin-right :10px;
  }
  .color-list .color-item.blue{
    background-color: #1E9FFF;
  }
  .color-list .color-item.yellow{
    background-color: rgb(254, 185, 0);
  }
  .color-list .color-item.green{
    background-color: #009688;
  }
  .color-list .color-item.red{
    background-color: #ed4014;
  }
  .proCoupon{
    ::v-deep.el-form-item__content{
      margin-top: 5px;
    }
  }
  .tabPic{
    width: 40px !important;
    height: 40px !important;
    img{
      width: 100%;
      height: 100%;
    }
  }
  .noLeft{
    ::v-deep.el-form-item__content{
      margin-left: 0 !important;
    }
  }
  .tabNumWidth{
    ::v-deep.el-input-number--medium{
      width: 121px !important;
    }
    ::v-deep.el-input-number__increase{
      width: 20px !important;
      font-size: 12px !important;
    }
    ::v-deep.el-input-number__decrease{
      width: 20px !important;
      font-size: 12px !important;
    }
    ::v-deep.el-input-number--medium .el-input__inner {
      padding-left: 25px !important;
      padding-right: 25px !important;
    }
    ::v-deep thead{
      line-height: normal !important;
    }
    ::v-deep .el-table .cell{
      line-height: normal !important;
    }
  }
  .selWidth{
    width: 100%;
  }
  .selWidthd{
    width: 300px;
  }
  .button-new-tag {
    height: 28px;
    line-height: 26px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }
  .pictrue{
    width: 60px;
    height: 60px;
    border: 1px dotted rgba(0,0,0,0.1);
    margin-right: 10px;
    position: relative;
    cursor: pointer;
    img{
      width: 100%;
      height: 100%;
    }
    video{
      width: 100%;
      height: 100%;
    }
  }
  .btndel{
    position: absolute;
    z-index: 1;
    width :20px !important;
    height: 20px !important;
    left: 46px;
    top: -4px;
  }
  .labeltop{
    ::v-deep.el-form-item__label{
      float: none !important;
      display: inline-block !important;
      width: auto !important;
    }
  }
  .iview-video-style {
  width: 300px;
  height: 180px;
  border-radius: 10px;
  background-color: #707070;
  margin: 0 120px 20px;
  position: relative;
  overflow: hidden;
}

.iview-video-style .iconv {
  color: #fff;
  line-height: 180px;
  width: 50px;
  height: 50px;
  display: inherit;
  font-size: 26px;
  position: absolute;
  top: -74px;
  left: 50%;
  margin-left: -25px;
}

.iview-video-style .mark {
  position: absolute;
  width: 100%;
  height: 30px;
  top: 0;
  background-color: rgba(0, 0, 0, 0.5);
  text-align: center;
}
</style>
